<script>
import {getToken, removeToken} from "@/store/token";

export default {
  props: ["orderId"],
  data() {
    return {
      payVisible: true,
      payment: {
        payment: "http://localhost:8088/img/1.jpg"
        //payment: "http://8.137.55.141/img/1.jpg"
      }
    }
  }, methods: {
    toPay(k) {
      if (k === "add") {
        let strings = this.payment.payment.split("/");
        let pay = strings[strings.length - 1].split(".")[0];
        this.$api.order.updateOrder(
            this.orderId,
            pay,
            JSON.parse(getToken("user")).id,
            2
        ).then(res => {
          if (res.data.success) {
            this.$message({
              message: '支付成功',
              type: 'success'
            });
          } else {
            this.$message({
              message: '服务器原因，支付失败，若已经支付成功请联系管理员',
              type: 'error'
            });
          }
        }).catch(res => {
          this.$message({
            message: '服务器端错误，若已经支付成功请联系管理员',
            type: 'error'
          });
        })
      } else {
        this.$message({
          message: '请尽快支付',
          type: 'warning'
        });
      }
      this.payVisible = false
    }
  },
  watch: {
    payVisible() {
      this.$emit('changeVal', this.payVisible)
    }
  }
}
</script>

<template>
  <el-dialog title="支付方式" :visible.sync="payVisible">
    <el-form :model="payment" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item>
        <el-radio-group v-model="payment.payment">
          <el-radio-button label="http://8.137.55.141:8080/img/1.jpg">微信支付</el-radio-button>
          <el-radio-button label="http://8.137.55.141:8080/img/2.jpg">支付宝支付</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-image style="width: 200px;" :src="payment.payment"></el-image>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="toPay('add')">确定</el-button>
        <el-button @click="toPay('can')">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<style scoped>

</style>